
(** An interface to the CFSQP nonlinear optimization library.  *)

val repeat : int ref
(** number of times to repeat optimization 
    (return the smallest (resp. largest) value *)

val minimize : (float array -> float) -> (int -> float array -> float) ->
                 int -> float array -> float array -> float * float array


val maximize : (float array -> float) -> (int -> float array -> float) ->
                  int -> float array -> float array -> float * float array
(** 
maximize obj cnstrs dim low hi 

estimates the optimal value of the [dim] dimensional objective function [obj]
taken on the domain [low < X < hi], such that the constraints
[constrs] are satisfied.  A constraint is satisfied if the value at a point
is negative.  For instance to optimize 

f [|x;y;z|] =  x^2 + y^2 + z^2 

provided that  

2 * x < y /\  2*y < z 

with bounds 

1 < x,y,z < 8

then we would write 

let rec pow x n = 
  match n with
      0 -> 1.
    | _ -> x *. pow x (n-1);;

let f0 xs = 
  let x0 = Array.get xs 0 in 
  let x1 = Array.get xs 1 in 
  let x2 = Array.get xs 2 in 
    pow x0 2 +. pow x1 2 +. pow x2 2;;

let c0 which xs = 
  let x0 = Array.get xs 0 in 
  let x1 = Array.get xs 1 in 
  let x2 = Array.get xs 2 in 
    match which with 
        1 -> 
          2. *. x0 -. x1
      | 2 -> 
          2. *. x1 -. x2
      | _ -> failwith "c0";;

print_float (fst (C.minimize f0 c0 2 [| 1.;1.;1.|] [| 8.;8.;8.|]));;

NOTE: Indices to the constraint function start at 1, indexing into
    an array should decrment the constraint argument.

 *)

val simple_min : (float array -> float) -> float array -> float array -> float * float array

val very_simple_min : (float array -> float) -> int -> float -> float -> float * float array

val simple_max : (float array -> float) -> float array -> float array -> float * float array

val very_simple_max : (float array -> float) -> int -> float -> float -> float * float array

